package com.qianbao.qianbaobusiness.ui.invoice;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.androidbase.widget.recycleadpter.BaseRecycleViewAdapter;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.ContractListBean;

public class ContractListRvAdapter extends BaseRecycleViewAdapter<ContractListBean.ResultBean> {
    private ItemClickListen mListen;

    public ContractListRvAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindBaseViewHolder(final RecyclerView.ViewHolder holder, final ContractListBean.ResultBean item) {
        VH vh = (VH) holder;
        vh.mTvTitle.setText(item.getContractName());
        switch (item.getContType()) {
            case 0:
                vh.mIvHead.setImageResource(R.drawable.icon_contract_qb);
                break;
            case 1:
                vh.mIvHead.setImageResource(R.drawable.icon_contract_wlb);
                break;
            case 2:
                vh.mIvHead.setImageResource(R.drawable.icon_contract_bl);
                break;
            case 3:
                vh.mIvHead.setImageResource(R.drawable.icon_contract_kayou);
                break;
            default:
                vh.mIvHead.setImageResource(R.drawable.icon_contract_qb);
                break;
        }
        if (item.getState() == 1) {
            vh.mIvState.setImageResource(R.drawable.icon_state_contract_unsigned);
        } else {
            vh.mIvState.setImageResource(R.drawable.icon_state_contract_signed);
        }
        vh.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListen == null) {
                    return;
                }
                mListen.itemClick(mData.indexOf(item));
            }
        });
    }

    @Override
    protected VH onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_contract_list, parent, false);
        return new VH(view);
    }

    @Override
    protected int getBaseItemViewType(int position) {
        return 0;
    }

    class VH extends RecyclerView.ViewHolder {

        ImageView mIvHead;
        TextView  mTvTitle;
        ImageView mIvState;

        public VH(View itemView) {
            super(itemView);
            mIvHead = (ImageView) itemView.findViewById(R.id.iv_head);
            mTvTitle = (TextView) itemView.findViewById(R.id.tv_name);
            mIvState = itemView.findViewById(R.id.iv_state);
        }
    }

    public interface ItemClickListen {
        void itemClick(int l);
    }

    public void setOnClickListen(ItemClickListen listen) {
        this.mListen = listen;
    }
}
